<template>
  <a-modal
    :title="`${model ? '编辑' : '新增'}角色`"
    :width="640"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <!-- 检查是否有 id 并且大于0，大于0是修改。其他是新增，新增不显示主键ID -->
        <a-form-item v-show="model && model.id > 0" label="主键ID">
          <a-input v-decorator="['id', { initialValue: 0 }]" disabled />
        </a-form-item>
        <a-form-item label="角色名称">
          <a-input
            v-decorator="['name', { rules: [{ required: true, message: '请输入角色名称！' }] }]"
            placeholder="请填写角色名称"
          />
        </a-form-item>
        <a-form-item label="角色描述">
          <a-input
            v-decorator="['desc', { rules: [{ required: true, message: '请输入角色描述！' }] }]"
            placeholder="请填写角色描述"
          />
        </a-form-item>
        <a-form-item label="服务商可有">
          <a-select v-decorator="['status', { initialValue: 0 }]" placeholder="请选择">
            <a-select-option :value="0">否</a-select-option>
            <a-select-option :value="1">有</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import formModalMixin from '@/mixins/formModalMixin'
import { roleAdd, roleEdit } from '@/api/role'
const fields = ['name', 'id', 'status', 'desc']
export default {
  mixins: [formModalMixin],
  data () {
    this.fields = fields
    this.editAction = roleEdit
    this.addAction = roleAdd
    return {}
  }
}
</script>
